package fnord.network;


public enum OrderType {
	CHAT, GAME_STATE, MONEY_REQUEST, ERROR, ATTACK, TRANSFER_CARD, TRANSFER_MONEY, SPEND_MONEY, ACTION, QUIT, PASS;
	
	public static OrderType getTypeFor(String s) {
		if(s.equals(NetworkConstants.PROTOCOL_CHT)) return CHAT;
		if(s.equals(NetworkConstants.PROTOCOL_GST)) return GAME_STATE;
		if(s.equals(NetworkConstants.PROTOCOL_MRQ)) return MONEY_REQUEST;
		if(s.equals(NetworkConstants.PROTOCOL_ERR)) return ERROR;
		if(s.equals(NetworkConstants.PROTOCOL_ATK)) return ATTACK;
		if(s.equals(NetworkConstants.PROTOCOL_TRC)) return TRANSFER_CARD;
		if(s.equals(NetworkConstants.PROTOCOL_TRM)) return TRANSFER_MONEY;
		if(s.equals(NetworkConstants.PROTOCOL_SPM)) return SPEND_MONEY;
		if(s.equals(NetworkConstants.PROTOCOL_ACT)) return ACTION;
		if(s.equals(NetworkConstants.PROTOCOL_QIT)) return QUIT;
		if(s.equals(NetworkConstants.PROTOCOL_PAS)) return PASS;
		return ERROR;
		
	}
	
	public String getString() {
		switch(this) {
		case CHAT:
			return NetworkConstants.PROTOCOL_CHT;
		case GAME_STATE:
			return NetworkConstants.PROTOCOL_GST;
		case MONEY_REQUEST:
			return NetworkConstants.PROTOCOL_MRQ;
		case ERROR:
			return NetworkConstants.PROTOCOL_ERR;
		case ATTACK:
			return NetworkConstants.PROTOCOL_ATK;
		case TRANSFER_CARD:
			return NetworkConstants.PROTOCOL_TRC;
		case TRANSFER_MONEY:
			return NetworkConstants.PROTOCOL_TRM;
		case SPEND_MONEY:
			return NetworkConstants.PROTOCOL_SPM;
		case ACTION:
			return NetworkConstants.PROTOCOL_ACT;
		case QUIT:
			return NetworkConstants.PROTOCOL_QIT;
		case PASS:
			return NetworkConstants.PROTOCOL_PAS;
		default:
			return NetworkConstants.PROTOCOL_ERR;
			
		}
	}
	
	public boolean sentByServer() {
		switch(this) {
		case CHAT:case GAME_STATE:case MONEY_REQUEST:case ERROR: case QUIT:
			return true;
		default:
			return false;	
		}
	}
	
	public boolean sentByClient() {
		switch(this) {
		case CHAT:case ATTACK:case TRANSFER_CARD:case TRANSFER_MONEY:case SPEND_MONEY:case ACTION: case QUIT: case PASS:
			return true;
		default:
			return false;	
		}
	}

	public boolean toAll() {
		switch(this) {
		case CHAT:case GAME_STATE: case QUIT:
			return true;
		default:
			return false;	
		}
	}

	public boolean isOrder() {
		switch(this) {
		case ATTACK:case TRANSFER_CARD:case TRANSFER_MONEY:case SPEND_MONEY:case PASS:
			return true;
		default:
			return false;	
		}
	}
}
